package com.yet.kotlinapp.modules.regist

import com.blankj.utilcode.util.LogUtils
import com.kongzue.dialogx.dialogs.WaitDialog
import com.yet.kotlinapp.api.WangAndroidApi
import com.yet.kotlinapp.entity.LoginResponseInfo
import com.yet.kotlinapp.modules.regist.inter.RegistModel
import com.yet.kotlinapp.modules.regist.inter.RegistPresenter
import com.yet.kotlinapp.net.ApiClient
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observer
import io.reactivex.rxjava3.core.Scheduler
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers

/**
 *
 * @ProjectName: Kotlin app
 * @Package: com.yet.kotlinapp.modules.regist
 * @ClassName: RegistModelImp
 * @Description: java类作用描述
 * @Author: liys
 * @CreateDate: 2021/8/30 10:46
 * @UpdateUser: 更新者
 * @UpdateDate: 2021/8/30 10:46
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
class RegistModelImp :RegistModel {

    override fun onRegist(
        user: String,
        pw: String,
        pw2: String,
        onresult: RegistPresenter.onRegistCallback
    ) {
        ApiClient.instance.instanceRetrofit(WangAndroidApi::class.java)
            .registAction(user,pw,pw2)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object :Observer<LoginResponseInfo>{
                override fun onSubscribe(d: Disposable?) {
                  WaitDialog.show("注册中")
                }

                override fun onNext(t: LoginResponseInfo?) {
                   LogUtils.d(t.toString())
                    if(t?.data==null){
                        onresult.onFairl(t!!.errorMsg)
                    }else{
                        onresult.onSuccess()
                    }
                }

                override fun onError(e: Throwable?) {
                  LogUtils.d(e?.message)
                    WaitDialog.dismiss()
                }

                override fun onComplete() {
                    WaitDialog.dismiss()
                }

            })
    }
}